package com.li.flink.datastream

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.util.NumberSequenceIterator

object ParallelismOp {
  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val text = env.socketTextStream("bigdata04", 9001)
    //DataStream并行度
    println(text.parallelism)
    //env并行度
    //    println(env.getParallelism)
    env.setParallelism(2) //上下文并行度作用于全局，算子不自定义设置时，则读取全局并行度

    val wordCount = text.flatMap(_.split(" ")) //将每一行数据根据空格切分单词
    // 默认读取全局并行度
    //    println(wordCount.parallelism)
    //主动设置
    wordCount.setParallelism(4)
    println(wordCount.parallelism)

    val env2 = StreamExecutionEnvironment.getExecutionEnvironment

    val iter = new NumberSequenceIterator(1, 10)
    //并行集合，可以设置并行度
    val list = env2.fromParallelCollection(iter)
    list.setParallelism(3)
    print(env2.getParallelism)
    print(list.parallelism)

  }
}
